import 'package:flutter/material.dart';
import 'package:flutter_application_1/config/app_colors.dart';
import 'package:flutter_application_1/models/user_model.dart';
import 'package:flutter_application_1/utils/utils.dart';

class SingerCard extends StatelessWidget {
  final UserItem userItem;
  const SingerCard({Key? key, required this.userItem}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Column(
        children: [
          AspectRatio(
            aspectRatio: 1 / 1,
            child: ClipRRect(
              borderRadius: BorderRadius.circular(10),
              child: FadeInImage.assetNetwork(
                placeholder: "assets/images/common/lazy-1.png",
                image: userItem.coverPictureUrl,
                fit: BoxFit.cover,
              ),
            ),
          ),
          Container(
            padding: const EdgeInsets.only(top: 6),
            child: Text(
              userItem.nickname,
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: const TextStyle(
                color: Colors.black54,
                fontSize: 16,
              ),
            ),
          ),
          Row(
            children: [
              _iconText(
                  "assets/images/icons/music.png", "歌曲", userItem.musicCount),
              _iconText("assets/images/icons/read.png", "播放",
                  userItem.musicPlayCount),
            ],
          ),
        ],
      ),
    );
  }

  Widget _iconText(String icon, String label, int count) {
    return Expanded(
      child: Row(
        children: [
          Image.asset(
            icon,
            width: 20,
            height: 20,
          ),
          const SizedBox(
            width: 3,
          ),
          Expanded(
            child: Text(
              "$label" + " " + countToString(count).toString(),
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: const TextStyle(
                color: AppColors.unactive,
                fontSize: 14,
              ),
            ),
          )
        ],
      ),
    );
  }
}
